/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: KeyInfo
 * @Package com.rx.core.bean
 * @Description: 公钥及UUID
 * @author: 陈锦韬
 * @date: 2021\6\25 0025
 * @version V1.0
 * @Copyright: 2021 陈锦韬  All rights reserved.
 */
package com.rx.core.bean;

import cn.hutool.core.util.HexUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bouncycastle.jcajce.provider.asymmetric.rsa.BCRSAPrivateCrtKey;
import org.bouncycastle.jcajce.provider.asymmetric.rsa.BCRSAPublicKey;

import java.security.PublicKey;
import java.util.UUID;

/**
 * @author: Administrator
 * @Description: 公钥及UUID
 * @date: 2021\6\25 0025
 */
@Data
public class KeyInfo {
    String uuid;
    String modulus;
    String publicExponent;
    String encoded;


    public static KeyInfo build(PublicKey publicKey){
        KeyInfo keyInfo = new KeyInfo();
        BCRSAPublicKey rsaBublicKey = (BCRSAPublicKey)publicKey;
        keyInfo.modulus =  rsaBublicKey.getModulus().toString(16);
        keyInfo.publicExponent =  rsaBublicKey.getPublicExponent().toString(16);
        keyInfo.encoded = HexUtil.encodeHexStr(rsaBublicKey.getEncoded());
        keyInfo.setUuid(UUID.randomUUID().toString());
        return keyInfo;
    }
}
